﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet"
        type="text/css" />
    <script src="../../../lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
    <script src="../TreeDeptData.js" type="text/javascript"></script>
    <script type="text/javascript">
        function alert(message)
        {
            $.ligerDialog.alert(message.toString(), '提示信息');
        }
        function tip(message)
        {
            $.ligerDialog.tip({ title: '提示信息', content: message.toString() });
        }
        var manager;
        $(function ()
        {
            manager = $("#maingrid").ligerGrid({
                columns: [
                    { display: '部门名', name: 'name', width: 250, align: 'left', editor: { type: 'text'} },
                { display: '部门标示', name: 'id', width: 250, type: 'int', align: 'left' },

                { display: '部门描述', name: 'remark', width: 250, align: 'left', editor: { type: 'text'} }
                ], width: '100%', pageSizeOptions: [5, 10, 15, 20], height: '97%',
                onSelectRow: function (rowdata, rowindex)
                {
                    $("#txtrowindex").val(rowindex);
                },
                data: TreeDeptData, alternatingRow: false, tree: { columnName: 'name' }, checkbox: false,
                autoCheckChildren: false
            }
            );
        });
        function deleteRow()
        {
            var row = manager.getSelectedRow();
            manager.deleteRow(row);
        }
        var i = -1;
        function getNewData(withchildren)
        {
            i++;
            var dept = $("#txtDept").val();
            var data = {
                name: dept + i,
                id: dept + i,
                remark: dept + i
            };
            if (withchildren)
            {
                data.children = [];
                data.children.push(getNewData());
                data.children.push(getNewData());
                data.children.push(getNewData());
            }
            return data;
        }
        //parent:是否增加到当前节点下面
        function addRow(withchildren)
        {
            var data = getNewData(withchildren);
            var selectRow = manager.getSelectedRow();
            var parentRow = selectRow;

            if (manager.isLeaf(parentRow))
            {
                tip('叶节点不能增加子节点');
                return;
            }


            manager.add(data, null, true, parentRow);
        }
        function appendToCurrentNodeUp()
        {
            var selectRow = manager.getSelectedRow();
            if (!selectRow) return;
            var selectRowParnet = manager.getParent(selectRow);
            var data = getNewData();
            manager.add(data, selectRow, true, selectRowParnet);
        }
        function appendToCurrentNodeDown()
        {
            var selectRow = manager.getSelectedRow();
            if (!selectRow) return;
            var selectRowParnet = manager.getParent(selectRow);
            var data = getNewData();
            manager.add(data, selectRow, false, selectRowParnet);
        }
        function getSelected()
        {
            var row = manager.getSelectedRow();
            if (!row) { alert('请选择行'); return; }
            alert(JSON.stringify(row));
        }
        function getData()
        {
            var data = manager.getData();
            alert(JSON.stringify(data));
        }
        function hasChildren()
        {
            var row = manager.getSelected();
            alert(manager.hasChildren(row));
        }
        function upgrade()
        {
            var row = manager.getSelected();
            manager.upgrade(row);
        }
        function demotion()
        {
            var row = manager.getSelected();
            manager.demotion(row);
        }
        function isLeaf()
        {
            var row = manager.getSelected();
            alert(manager.isLeaf(row));
        }
        function toggle()
        {
            var row = manager.getSelected();
            manager.toggle(row);
        }
        function expand()
        {
            var row = manager.getSelected();
            manager.expand(row);
        }
        function up()
        {
            var row = manager.getSelected();
            manager.up(row);
        }
        function down()
        {
            var row = manager.getSelected();
            manager.down(row);
        }
         
    </script>
    <style type="text/css">
    .l-button{width: 120px; float: left; margin-left: 10px; margin-bottom:2px; margin-top:2px;}
    </style>
</head>
<body style="padding: 4px">
    <div>
        <div style="margin: 2px;">
            【增加节点选项】 部门：
            <input type="text" value="新部门" id="txtDept" />
        </div>
        <a class="l-button"  onclick="deleteRow()">
            删除选择的行</a> 
    <a class="l-button" onclick="addRow()">增加节点</a> 
    <a class="l-button" onclick="addRow(true)" style="width: 150px;">增加节点(附加子节点)</a>
    <a class="l-button" onclick="appendToCurrentNodeUp()" style="width: 150px;">增加节点到同级别(上方)</a>
    <a class="l-button" onclick="appendToCurrentNodeDown()" style="width: 150px;">增加节点到同级别(下方)</a> 
    <a class="l-button" onclick="upgrade()">升级</a> 
    <a class="l-button" onclick="demotion()">降级</a> 
    <a class="l-button" onclick="expand()">伸展</a> 
    <a class="l-button" onclick="toggle()">伸展/收缩节点</a>
    <a class="l-button" onclick="up()">上移</a> 
    <a class="l-button" onclick="down()">下移</a> 
    <a class="l-button" onclick="isLeaf()">是否叶节点节点</a> 
    <a class="l-button" onclick="getSelected()">获取选中的值(选择行)</a> 
    <a class="l-button" onclick="getData()">获取当前的值</a>
        <div class="l-clear">
        </div>
    </div>
    <div id="maingrid">
    </div>
    <div>
    </div>
</body>
</html>
